var http = require("./http");
var process = require("./process");
var io = require("./io");

http.setRequestCallback(function (request_id, request) {
  var type = "request";
  var data = { url: request.url, method: request.method };
  process.write(request_id, type, data);
});

process.setReadCallback(function (data) {
  // console.log("process", data);
  if (data.type == "response") {
    http.sendResponse(data.request_id, data.data);
  } else {
    if (typeof io[data.type] == "function") {
      io[data.type](data.data, function (content) {
        process.write(data.request_id, data.type, content);
      });
    }
  }
});
